package com.sjgl.esdn.utils;

import java.io.*;
import java.util.LinkedList;

public class RTFUtils {

    /**
     * 将富文本转存为txt文件
     * @param content
     */
    public static void RTF2txt(String content,String path){
        FileWriter fileWriter = null;
        try {
            fileWriter = new FileWriter(path);
            fileWriter.write(content);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileWriter.flush();
                fileWriter.close();
            }catch (IOException ex){
                ex.printStackTrace();
            }
        }
    }

    /**
     * 获取富文本转存的txt文件中的内容
     * @param path
     * @return
     */
    public static String[] readRTF(String path){
        File source = new File(path);
        LinkedList<String> arr = new LinkedList<String>();
        BufferedReader br = null;
        try{
            br = new BufferedReader(new FileReader(source));
            String info = null;
            while((info = br.readLine()) != null){
                arr.add(info);
            }
        }catch(FileNotFoundException e){
            System.err.println("文件未找到");
        }catch(IOException e){
            System.err.println("文件读取出错");
        }catch(Exception e){
            System.err.println(e.getMessage());
        }finally{
            try{
                br.close();
            }catch(IOException e){
                System.err.println(e.getMessage());
            }
        }
        String[] results = new String[arr.size()];
        arr.toArray(results);
        return results;
    }

}
